package boot.util;

import boot.model.wxResEntity;
import boot.service.wxUserService;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import io.jsonwebtoken.Claims;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

/**
 * @author cb
 * @create 2022-09-13-17:33
 */
@Component
public class wxUtils {
//    public static Map getOpenId(String appid, String secret, String code) {
//        String path = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=" + appid +
//                "&secret=" + secret + "&code=" + code + "&grant_type=authorization_code";
//        String res[] = requestJson(path);
//        JSONObject jsonObject = JSON.parseObject(res[0]);
//        String openid = jsonObject.getString("openid");
//        String access_token = jsonObject.getString("access_token");
//        Map<String, Object> map = new HashMap<>();
//        map.put("openid", openid);
//        map.put("access_token", access_token);
//
//        return map;
//    }
//    @Autowired
//    private static wxUserService wxUserService;
//    public static int getUserIdbytoken(String token) throws Exception{
//        Claims claims = JwtUtil.parseJWT(token);
//        assert claims != null;
//        wxResEntity wxResEntity = JSON.parseObject(claims.getSubject(), boot.model.wxResEntity.class);
//        String openid = wxResEntity.getOpenid();
//        return wxUserService.getIdByOpenId(openid);
//    }
}
